<?php

use console\db\Migration;

/**
 * 创建应用基础相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m150104_091310_t_base extends Migration {

    /**
     * 应用配置信息表
     * @table `base_config`
     */
    public function buildTableBaseConfig() {
        return [
            'comment' => '应用配置信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'type_id' => $this->smallInteger(6)->unsigned()->notNull()->defaultValue(0)->comment('类型ID'),
                'name' => $this->char(64)->notNull()->comment('字段名'),
                'format' => $this->char(64)->notNull()->comment('格式'),
                'value' => $this->text()->notNull()->comment('值'),
                'label' => $this->string(100)->notNull()->comment('标签名称'),
                'input_type' => $this->char(64)->comment('输入框类型'),
                'setting' => $this->text()->comment('字段配置信息'),
                'description' => $this->string(255)->comment('描述'),
                'site_id' => $this->smallInteger(6)->unsigned()->notNull()->defaultValue(0)->comment('隶属站点ID'),
                'disabled' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('开启状态：0开启，1关闭'),
            ]
        ];
    }

    /**
     * 自由选项扩展信息表
     * @table `base_options`
     */
    public function buildTableBaseOptions() {
        return [
            'comment' => '自由选项扩展信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'scope' => $this->char(64)->notNull()->comment('应用范围名称'),
                'name' => $this->string(64)->notNull()->comment('名称'),
                'value' => $this->string(255)->comment('值'),
                'listorder' => $this->smallInteger(6)->unsigned()->notNull()->defaultValue(0)->comment('显示排序'),
                'disabled' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('开启状态：0开启，1关闭'),
            ],
            'index' => [
                [
                    'name' => 'idx_base_options_scope_name',
                    'unique' => true,
                    'columns' => ['scope', 'name'],
                ]
            ]
        ];
    }

    /**
     * 证件类型信息表
     * @table `base_idcard_type`
     */
    public function buildTableBaseIdcardType() {
        return [
            'comment' => '证件类型信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(50)->notNull()->comment('类型名称'),
                'label' => $this->char(50)->defaultValue('')->comment('标识'),
                'pattern' => $this->char(255)->defaultValue('')->comment('正则校验表达式'),
                'disabled' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('禁用状态：0开启，1关闭'),
            ]
        ];
    }

}
